package com.icode.core.shared;

import com.icode.core.dto.house.HouseWeekTimeDTO;
import com.icode.core.dto.manager.ReserveDTO;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-6-26
 * Time: 下午2:32
 * To change this template use File | Settings | File Templates.
 */
public class ReserveDateHandle {

    public static Map<Object, String> DateLimit() {
        String limit = "2015-02-12~2015-03-04,2015-10-01~2015-10-07";
        String minDate = limit.substring(0, 10);
        String[] timeNum = limit.split(",");
        String maxDate = timeNum[timeNum.length - 1].split("~")[1];
        String disabledDates = "";
        return null;
    }

    public static Set<Integer> getMonths(ReserveDTO reserveDTO) {
        Set<Integer> months = new TreeSet();
        List<HouseWeekTimeDTO> list = reserveDTO.getHouseWeekDTO().getHouseWeekTimeDTOs();
        list = exceptUselessHouseWeekTime(list);
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            HouseWeekTimeDTO dto = (HouseWeekTimeDTO) iterator.next();
            months.add(Integer.valueOf(dto.getMonth()));
        }
        return months;
    }


    public static List<HouseWeekTimeDTO> exceptUselessHouseWeekTime(List<HouseWeekTimeDTO> houseWeekTimeDTOs) {
        List<HouseWeekTimeDTO> list = new ArrayList<>();
        try {
            for (HouseWeekTimeDTO h : houseWeekTimeDTOs) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date current = new Date();
                current = HouseWeekHandle.getInternalDateByDay(current, 15);
                Date date = sdf.parse(h.getEnd());
                boolean flag = current.after(date);
                if (!flag) {
                    list.add(h);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return list;
    }

}
